package demo1;


class Base{
    public String name;
    public int age;

   /* public Base(){
        System.out.println("Base()");//无参的构造方法
    }*/

    //带有两个参数的构造方法
    public Base(String name,int age){
        this.name = name;
        this.age = age;
        System.out.println("Base()");
    }

}
class Derived extends Base{
    public String color;
   /* public Derived(){
        super();
        //必须在第一行
        //子类的构造方法中默认会调用无父类参的构造方法：super（）
        //用户没有写时，编译器会自动添加，而且super（）必须是子类构造方法中第一条语句，并且只能出现一次
        System.out.println("Derived()")
    }*/
    public Derived(String name,int age,String color){
        super(name,age);//必须在第一行  调用父类的带有两个参数的构造方法来 初始化父类当中成员
        this.color = color;
        System.out.println("Derived()");
    }
}

 class Base1{
    int a;
    int b;
    public void methodA(){
        System.out.println("Base1中的methodA()");
    }
     public void methodB(){
         System.out.println("Base1中的methodB()");
     }
}
class Derived1 extends Base1{
     int a;
     char b;
     public void methodA(int a) {
         System.out.println("Derived1中的method方法");
     }
    public void methodB(){
        System.out.println("Base1中的methodB()");
    }
    public void methodC(){
         a = 100;
         b = 101;

         super.a = 200;
         super.b = 201;

         methodA();
         methodA(20);

         methodB();
         super.methodB();
    }
}
class Animal {
    String name;
    int age;
    public void eat(){
        System.out.println(name + "正在吃。。。");
    }
}
class Dog extends Animal {
    public String color;
    public void barks(){
        System.out.println(name + "正在叫。。。");
    }
}
class Cat extends Animal {
    public void miaomiao(){
        System.out.println(name + "正在喵喵叫。。。");
    }
}

class Shape{
    public void draw(){
        System.out.println("画图");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}
class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("🔺");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("⭕");
    }
}

public class TestAnimal {
    public static void main(String[] args) {
        /*Rect rect = new Rect();//子类对象
        Triangle triangle = new Triangle();
        Cycle cycle = new Cycle();
        Shape[] shapes = {cycle,rect,cycle,rect,triangle};//父类类型*/

        Shape rect = new Rect();//向上转型
        Shape triangle = new Triangle();
        Shape cycle = new Cycle();
        Shape[] shapes = {cycle,rect,cycle,rect,triangle};
        //遍历数组
        for (Shape shape:shapes) {
            shape.draw();
        }

    }


    public static void main2(String[] args) {

        Derived d = new Derived("旺财",2,"白色");
    }
    public static void main1(String[] args) {
        Dog dog = new Dog();
        //Dog类中没有定义任何成员变量，name和age属性 肯定是从父类Animal中继承下来的
        dog.name = "旺财";
        dog.age = 3;
        //dog访问的eat方法也是从Animal中继承下来的
        dog.eat();
    }
}
